package in.muton.edushare.panels.upload.uploadify.demo;

import in.muton.edushare.panels.upload.uploadify.UploadifyProcessPage;

import java.io.File;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.util.upload.FileItem;

public class UploadifyDemoProcessingPage extends UploadifyProcessPage {

	private static Log log = LogFactory.getLog(UploadifyDemoProcessingPage.class);
	
	public UploadifyDemoProcessingPage(PageParameters params) {
		super(params);
	}

	@Override
	public void processFile(FileItem fileItem) {
		FileUpload upload = new FileUpload(fileItem);
		try {
			log.debug("Processing: " + fileItem.getName());
			upload.writeTo(new File("/home/naishe/EduShare/testUpload/"+ fileItem.getName().substring(0, fileItem.getName().lastIndexOf(".")) + (int)(Math.random()*10000)+fileItem.getName().substring(fileItem.getName().lastIndexOf("."))));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
